﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;

namespace WebSite.UserSetting
{
    public partial class Broadcast : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadContent();
            }
        }

        #region 加载内容
        private void LoadContent()
        {
            string serverpath = System.Configuration.ConfigurationManager.AppSettings["ServerPath"] + "";
            //当前用户
            Users uinfo = UserBase.GetCurrentUser();
            string userid = uinfo.ID;
            string realmname = uinfo.RealmName;
            string indexinfo = uinfo.IndexInfo;
            string registerinfo = uinfo.RegisterInfo;
            string currentindex = indexinfo;
            string currentregister = registerinfo;

            //加载默认宣传语
            SystemConfig scinfo = new SystemConfig();
            SystemConfigHelper schelper = new SystemConfigHelper();
            scinfo = schelper.GetSystemConfig("1");
            string systemindexinfo = scinfo.IndexInfo;
            string recommandregisterinfo = scinfo.RecommandRegisterInfo;

            if (string.IsNullOrEmpty(realmname))
            {
                lbRealmName.Visible = true;
            }
            else
            {
                lbRealmName.Visible = false;
            }

            if (string.IsNullOrEmpty(currentindex))
            {
                if (string.IsNullOrEmpty(realmname))
                {
                    currentindex = systemindexinfo + serverpath + "/u/" + userid + ".aspx";
                }
                else
                {
                    currentindex = systemindexinfo + serverpath + "/u/" + realmname + ".aspx";
                }
            }
            if (string.IsNullOrEmpty(currentregister))
            {
                currentregister =recommandregisterinfo+ serverpath + "/Register.aspx?userid=" + userid;
            }

            txtIndex.Text = currentindex;
            txtRegister.Text = currentregister;
        }
        #endregion

        #region 保存个人首页信息
        protected void btnSaveIndex_Click(object sender, EventArgs e)
        {
            string indexinfo = txtIndex.Text.Trim();
            Users uinfo = UserBase.GetCurrentUser();
            uinfo.IndexInfo = indexinfo;
            UsersHelper uhelper = new UsersHelper();
            uhelper.EditUsers(uinfo);
            Tools.Alert("保存成功");
        }
        #endregion

        #region 保存推荐注册信息
        protected void btnSaveRegister_Click(object sender, EventArgs e)
        {
            string registerinfo = txtRegister.Text.Trim();
            Users uinfo = UserBase.GetCurrentUser();
            uinfo.RegisterInfo = registerinfo;
            UsersHelper uhelper = new UsersHelper();
            uhelper.EditUsers(uinfo);
            Tools.Alert("保存成功");
        }
        #endregion

        #region 设置个性域名
        protected void lbRealmName_Click(object sender, EventArgs e)
        {
            Response.Redirect("RealmNameSet.aspx");
        }
        #endregion
    }
}